package com.ruoyi.student_club.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.student_club.domain.ClubPoster;
import com.ruoyi.student_club.mapper.ClubPosterMapper;
import com.ruoyi.student_club.service.IClubPosterService;
import com.ruoyi.student_club.utils.UploadUtil;
import com.ruoyi.student_club.vo.ClubPictureVo;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;


/**
 * 首页轮播图Service业务层处理
 * 
 * @author 无尤
 * @date 2022-01-14
 */
@Service
public class ClubPosterServiceImpl extends ServiceImpl<ClubPosterMapper, ClubPoster> implements IClubPosterService {


    @Override
    public String uploadPoster(MultipartFile file) {
        String typeName = "clubPost";
        return UploadUtil.upload(file,typeName);
    }

    @Override
    public List<ClubPictureVo> getPoster() {
        SysUser current = ShiroUtils.getSysUser();
        Long clubId = current.getClubId();
        List<ClubPoster> posterList = baseMapper
                .selectList(new QueryWrapper<ClubPoster>().eq("club_id",clubId).orderByDesc("create_time"));
        List<ClubPictureVo> voList = new ArrayList<>();
        for (ClubPoster clubPoster : posterList) {
            ClubPictureVo vo = new ClubPictureVo();
            BeanUtils.copyBeanProp(vo,clubPoster);
            voList.add(vo);
        }
        return voList;
    }
}
